package com.example.JcGQS.util;

import cn.hutool.core.util.RandomUtil;
import java.time.Instant;
import java.util.concurrent.TimeUnit;

/**
 * 订单工具类
 *
 * @author 末日
 * @date 2023/11/21
 */
public class OrderUtil {


    /**
     * 创建订单号
     *
     * @return {@link String}
     */
    public static String createOrderNumber() {
        // 当前时间戳
        Instant now = Instant.now().plusMillis(TimeUnit.HOURS.toMillis(8L));
        String orderStr = String.valueOf(now.getEpochSecond());
        // 取出后8位
        //String substring = orderStr.substring(4);
        //System.out.println(substring);
        // 随机四尾数
        return orderStr + RandomUtil.randomInt(1000);
    }

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 100; i++) {
            Thread.sleep(1000);
            String orderNumber = OrderUtil.createOrderNumber();
            System.out.println(orderNumber);
        }
    }
}
